package org.hiucung.hlsdownloader.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters

// M3U8Database.kt
@Database(
    entities = [M3U8TaskItemEntity::class],
    version = 1,
    exportSchema = false
)
@TypeConverters(M3U8TaskStateConverters::class)
abstract class M3U8Database : RoomDatabase() {
    abstract fun m3u8TaskItemDao(): M3U8TaskItemDao

    companion object {
        @Volatile
        private var INSTANCE: M3U8Database? = null

        fun getInstance(context: Context): M3U8Database {
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    M3U8Database::class.java,
                    "hls_downloader.db"
                ).build()
                INSTANCE = instance
                instance
            }
        }
    }
}